<%@ page language="java" pageEncoding="UTF-8"
	errorPage="../../defaultException.jsp"%>
<%@include file="../../tags.jsp"%>
<html>
<head>
<title>目的地特色项信息管理</title>
<%@include file="../../head.jsp"%>

</head>
<body>

	<table id="list_data" cellspacing="0" cellpadding="0">
		<thead>
			<tr>
				<th field="operator" formatter="renderOperator">图文管理</th>
				<th field="zhname">中文标题</th>
				<th field="enname">英文标题</th>
				<th field="url">特色项链接地址</th>
				<th field="createTime">特色项创建时间</th>
				<th field="lat">纬度</th>
				<th field="lng">经度</th>
				<th field="tel">电话</th>
				<th field="address">地址</th>
				<th field="price">价格</th>
				<th field="email">邮箱</th>
				<th field="note">提示</th>
				<th field="openTime">开放时间</th>
				<th field="menu">菜单</th>
				<th field="stayTime">停留时间(分)</th>
				<th field="expireTime">失效时间</th>
				<th field="deleted" formatter="deleteStatus">删除状态</th>
				<th field="summary">描述摘要</th>

			</tr>
		</thead>
	</table>
	<script type="text/javascript">
	var deletestatus={
			'0' : '未删除',
			'1' : '已删除'
	};
		function deleteStatus(value, row, index) {
			return deletestatus[value];
		}
		function renderOperator(value,row,index){
			return "<a href='${cpath }/admin/dest/feature/item/text/vlist?featureItemId="+row.featureItemId+"'>图文管理</a>";
		}
	</script>

	<div id="addDestFeatureItemDialog"
		style="width: 400px; height: 280px; padding: 10px 20px" closed="true">
	</div>

	<script type="text/javascript">
		$('#list_data')
				.datagrid(
						{
							title : '独立发布特色项',
							iconCls : 'icon-edit',//图标 
							width : 1024,
							height : 500,
							doSize : true,
							nowrap : false,
							striped : true,
							border : true,
							collapsible : false,//是否可折叠的 
							fitColumns : true,//自动大小 
							fit : false,
							url : '${cpath }/admin/dest/alone/feature/item/list',
							//sortName: 'code', 
							//sortOrder: 'desc', 
							remoteSort : false,
							idField : 'featureItemId',
							singleSelect : true,//是否单选 
							pagination : true,//分页控件 
							rownumbers : true,//行号 
							//frozenColumns:[[ 
							//    {field:'ck',checkbox:true} 
							//]], 
							toolbar : [
									{
										text : '发布独立特色项',
										iconCls : 'icon-add',
										handler : function() {
											//openDialog("add_dialog","add");
											var saveAction = cpath
													+ '/admin/dest/alone/feature/item/save';
											var openAction = cpath
													+ '/admin/dest/alone/feature/item/vsave';
											openAddFeatureItemDialog('发布独立特色项',
													openAction, saveAction,
													addDestSuccess);
										}
									},
									'-',
									{
										text : '修改独立特色项',
										iconCls : 'icon-add',
										handler : function() {
											//openDialog("add_dialog","add");
											var saveAction = cpath
													+ '/admin/dest/alone/feature/item/update';
											var openAction = cpath
													+ '/admin/dest/alone/feature/item/vupdate';
											openUpdateFeatureItemDialog(
													'修改独立特色项', openAction,
													saveAction, addDestSuccess,
													getSelectFeatrueItem);
										}
									},
									'-',
									{
										text : '删除特色项',
										iconCls : 'icon-add',
										handler : function() {
											var deleteAction = cpath
													+ '/admin/dest/feature/item/delete';
											deleteFeatureItem(deleteAction,
													getSelectFeatrueItem);
										}
									}, '-', {
										text : '刷新',
										iconCls : 'icon-reload',
										handler : function() {
											$('#list_data').datagrid('reload');
											save_status = false;
										}
									} ]
						});
		//设置分页控件 
		var p = $('#list_data').datagrid('getPager');
		$(p).pagination({
			pageSize : 10,//每页显示的记录条数，默认为10 
			pageList : [ 5, 10, 15 ],//可以设置每页记录条数的列表 
			beforePageText : '第',//页数文本框前显示的汉字 
			afterPageText : '页    共 {pages} 页',
			displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录'
		/*onBeforeRefresh:function(){
		    $(this).pagination('loading');
		    alert('before refresh');
		    $(this).pagination('loaded');
		}*/
		});
	</script>
	<script type="text/javascript">
		var url;
		var cpath = '${cpath}';

		function getSelectFeatrueItem() {
			return $('#list_data').datagrid('getSelected');
		}

		function addDestSuccess() {
			$('#list_data').datagrid('reload'); // reload the user data
		}
		function openAddFeatureItemDialog(dlgtitle, openAction, saveAction,
				successCallback) {

			$('#addDestFeatureItemDialog').dialog({
				title : dlgtitle,
				width : 800,
				height : 550,
				closed : false,
				cache : false,
				resizable : true,
				href : openAction,
				modal : true,
				closed : true,
				buttons : [ {
					text : '保存',
					iconCls : "icon-ok",
					handler : function() {
						saveForm(saveAction, successCallback);
					}
				}, {
					text : '取消',
					iconCls : "icon-cancel",
					handler : function() {
						$('#addDestFeatureItemDialog').dialog('close');
						$('#list_data').datagrid('clearSelections');
					}
				} ]
			});
			$('#addDestFeatureItemDialog').dialog('open');
		}
		function openUpdateFeatureItemDialog(dlgtitle, openAction, saveAction,
				successCallback, selectRowHandler) {
			//修改特色项信息，先判断是否有选中特色项
			var row = selectRowHandler();
			//没有选中行，则需要提示
			if (!row) {
				$.messager.alert("提示", "请选择要操作特色项", "info");
				return;
			} else {
					openAction += '?featureItemId=' + row.featureItemId;
			}
			$('#addDestFeatureItemDialog').dialog({
				title : dlgtitle,
				width : 900,
				height : 550,
				closed : false,
				cache : false,
				resizable : true,
				href : openAction,
				modal : true,
				closed : true,
				buttons : [ {
					text : '保存',
					iconCls : "icon-ok",
					handler : function() {
						saveForm(saveAction, successCallback);
					}
				}, {
					text : '取消',
					iconCls : "icon-cancel",
					handler : function() {
						$('#addDestFeatureItemDialog').dialog('close');
						$('#list_data').datagrid('clearSelections');
					}
				} ]
			});
			$('#addDestFeatureItemDialog').dialog('open');
		}
		var save_status = false;
		function saveForm(saveAction, successCallback) {
			if (save_status) {
				$.messager.alert("提示", "请耐心等待。。。后台执行中。。。", "info");
				return;
			}
			save_status = true;
			$('#fm').form('submit', {
				url : saveAction,
				onSubmit : function() {
					var result = $(this).form('validate');
					if (!result) {
						save_status = false;
					}
					return result;
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.resultCode !== '00000000') {
						$.messager.alert("错误", result.resultMsg, "error");
						$('#list_data').datagrid('clearSelections');
					} else {
						$.messager.alert("成功", result.resultMsg, "info");
						$('#addDestFeatureItemDialog').dialog('close');
						if (successCallback) {
							successCallback();
						}
						$('#list_data').datagrid('clearSelections');
					}
					save_status = false;
				}
			});
		}

		function deleteFeatureItem(deleteAction, getSelectFeatrueItem) {
			var featureTypeId = '${feature.featureCategoryId}';
			deleteAction += '?featureCategoryId=' + featureTypeId;

			if (getSelectFeatrueItem) {

				var row = getSelectFeatrueItem();
				//没有选中行，则需要提示
				if (!row) {
					$.messager.alert("提示", "请选择要删除的特色项", "info");
					return;
				}
				if (row) {
					$.messager.confirm("提示", "确认要删除的特色项吗？", function(r) {
						if (r) {
							$.post(deleteAction, row,
									function(result) {
										if (result.resultCode === '00000000') {
											$('#list_data').datagrid('reload'); // reload the user data
											$.messager.alert("提示",
													result.resultMsg, "info");
											$('#list_data').datagrid(
													'clearSelections');
										} else {
											$.messager.alert("错误",
													result.resultMsg, "error");
											$('#list_data').datagrid(
													'clearSelections');
										}
									}, 'json');
						}
					});
				}
			}
		}
	</script>
	<style type="text/css">
#fm {
	margin: 0;
	padding: 40px 40px;
}

.ftitle {
	font-size: 14px;
	font-weight: bold;
	padding: 5px 0;
	margin-bottom: 10px;
	border-bottom: 1px solid #ccc;
}

.fitem {
	margin-bottom: 5px;
}

.fitem label {
	display: inline-block;
	width: 90px;
}
</style>
</body>
</html>